package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.ReportStoreDAO;
import com.xinghou.platform.model.main.ReportStore;

/**
 * @author liuwei.wen
 *
 */
@Service
public class ReportStoreDAOImpl  {/*

	@Resource
	private JdbcTemplate jdbcTemplate;
	
		@Override
		public ReportStore getReportStoreById(Integer Id) throws DataAccessException {
			CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
			String sql="SELECT 	Id,User_id,Store_id,Reason_id,Description,STATUS,Create_time FROM  report_store  where Id=?";
			ReportStore reportStore = jdbcTemplate.queryForObject(sql, new Object[] {Id}, new ReportStoreMapper());
			CustomerContextHolder.clearCustomerType();
			return reportStore;
		}

		@Override
		public int updateReportStore(ReportStore reportStore) throws DataAccessException {
			StringBuffer strSQL = new StringBuffer("UPDATE report_store SET User_id =?,Store_id =?,Reason_id =?,Description =?,STATUS =?,Create_time =? WHERE Id=?");					
			Object[] params = {reportStore.getUserId(),reportStore.getStatus(),reportStore.getReasonId(),reportStore.getDescription(),reportStore.getStatus(),reportStore.getCreateTime(),reportStore.getId()};
			CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
			int ret = jdbcTemplate.update(strSQL.toString(),params);
			CustomerContextHolder.clearCustomerType();
			return ret;
		}

		@Override
		public int saveReportStore(ReportStore reportStore) throws DataAccessException {
			StringBuffer strSQL = new StringBuffer("INSERT INTO report_store (User_id,Store_id,Reason_id,Description,STATUS,Create_time) VALUES(?,?,?,?,?,?);");			
			Object[] params = {reportStore.getUserId(),reportStore.getStoreId(),reportStore.getReasonId(),reportStore.getDescription(),reportStore.getStatus(),reportStore.getCreateTime()};
			CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
			int ret =jdbcTemplate.save(strSQL.toString(),params);
			CustomerContextHolder.clearCustomerType();
			return ret;
		}
     
		private static final class ReportStoreMapper implements RowMapper<ReportStore> {
			public ReportStore mapRow(ResultSet rs, int rowNum) throws SQLException {
				ReportStore reportStore = new ReportStore();
				reportStore.setCreateTime(rs.getDate("Create_time"));
				reportStore.setDescription(rs.getString("Description"));
				reportStore.setId(rs.getInt("Id"));
				reportStore.setReasonId(rs.getShort("Reason_id"));
				reportStore.setStatus(rs.getShort("STATUS"));
				reportStore.setStoreId(rs.getInt("Store_id"));
				reportStore.setUserId(rs.getInt("User_id"));
				return reportStore;
			}
		}*/
}
